package com.nervenets.shopping.hibernate.dao;

import com.nervenets.general.hibernate.dao.BaseDao;
import com.nervenets.shopping.hibernate.domain.common.GlobalRule;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface GlobalRuleDao extends BaseDao<GlobalRule> {
    GlobalRule findTopByEnableIsTrueAndDeletedOrderById(long deleted);

    @Modifying
    @Transactional
    @Query(value = "update GlobalRule SET enable = false ")
    void updateAllEnableToFalse();

    @Modifying
    @Transactional
    @Query(value = "update GlobalRule SET enable = :enable  where id = :id ")
    void updateGlobalRuleEnable(@Param("id") long id, @Param("enable") boolean enable);
}
